package com;


import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.ServletContextInitializer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.demo.util.ProperityUtil;
import com.demo.util.SpringContextUtil;

@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableConfigurationProperties(ProperityUtil.class)
@EnableTransactionManagement 
@Order(HIGHEST_PRECEDENCE)
@EnableScheduling
public class SpringSecuritySessionRedisUserDetailsServiceApplication extends
		SpringBootServletInitializer {

	@Bean
	public ServletContextInitializer servletContextInitializer() {
		return new ServletContextInitializer() {
			@Override
			public void onStartup(ServletContext servletContext)
					throws ServletException {
				//lightAdmin 初始化配置
//				LightAdmin.configure(servletContext)
//						.basePackage("com.demo.administration")
//						.baseUrl("/lightadmin").security(false)
//						.backToSiteUrl("/");
//				
				//启动时初始化springcontentUtil
				SpringContextUtil.setSpringContext(WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext));
				
//				new LightAdminWebApplicationInitializer()
//						.onStartup(servletContext);
			}
		};
	}

	public static void main(String[] args) throws Exception {
		SpringApplication.run(
				SpringSecuritySessionRedisUserDetailsServiceApplication.class,
				args);
	}

	@Override
	protected SpringApplicationBuilder configure(
			SpringApplicationBuilder application) {
		return application
				.sources(SpringSecuritySessionRedisUserDetailsServiceApplication.class);
	}
	
	
	
	 
}
